
window.addEvent('domready', function() {
  document.getElements('a').addEvent('focus', function() { this.blur(); } );
});


//----------------
function cv_togls(blk,act){
 if(act==1) {
   document.getElementById('b'+blk+'1').style.display="none";
   document.getElementById('b'+blk+'0').style.display="block";
 }
 else if(act==0){
   document.getElementById('b'+blk+'1').style.display="block";
   document.getElementById('b'+blk+'0').style.display="none";
 }
}
//
function cv_srch_go(){
var t=document.SearchForm.Search;
if(t.value!='SEARCH'&&t.value!='') document.SearchForm.submit();
}
//
function cv_clr_in(){
var t=document.SearchForm.Search;
if(t.value!='SEARCH') return;
else t.value='';
}
//----------------
function cv_ajx(url,pg_elmt,callMessage,err_msg){
 document.getElementById(pg_elmt).innerHTML=callMessage;
 try{req=new XMLHttpRequest(); /*Firefox*/}
 catch(e){try{req=new ActiveXObject("Msxml2.XMLHTTP"); /*IE*/}
  catch(e){try{req=new ActiveXObject("Microsoft.XMLHTTP"); /*IE*/}
   catch(e){req=false;} 
  }
 }
 req.onreadystatechange=function(){
  cv_resp(pg_elmt,err_msg);
 };
 req.open("GET",url,true);
 req.send(null);
}

function cv_resp(pg_elmt,err_msg){
 if(req.readyState==4){
  if(req.status==200){
   document.getElementById(pg_elmt).innerHTML=cv_throw(req.responseText);
  }
  else
   document.getElementById(pg_elmt).innerHTML=err_msg;
 }
}

function cv_throw(innerText){
//if(innerText.length==0) return "<br/><h3>No specifications available for this product at this time.</h3>"
var xmlDoc;
try{//IE
 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 xmlDoc.async="false";
 xmlDoc.loadXML(innerText);
}catch(e){
 try{//Firefox
  var parser=new DOMParser();
  xmlDoc=parser.parseFromString(innerText,"text/xml");
 }catch(e){alert(e.message);return;}
}
var sName='';
var re=/\u00A6\s/g;//with spaces \u00a6-unicode,166 dec
var re2=/\u00A6/g;//without spaces

var x=xmlDoc.getElementsByTagName("INTRO");
if(x.length&&x[0].hasChildNodes()){
 sName+="<div class=cv_intro>"+x[0].childNodes[0].nodeValue.replace(re2,"<br/>")+"</div>";
}
x=xmlDoc.getElementsByTagName("MSPEC");
if(x.length&&chlnk(x)){
 var xx=x[0].getElementsByTagName("M");
 if(xx.length!=0){
  sName+="<nobr id='cv_desc'>";
  sName+="<table>";
  sName+="<caption>Main Specification:</caption>";
  for(var j=0,cC=true;j<xx.length;j++,cC=!cC){
   var t1=xx[j].childNodes[0].hasChildNodes()?xx[j].childNodes[0].childNodes[0].nodeValue:'';
   var t2=xx[j].childNodes[1].hasChildNodes()?xx[j].childNodes[1].childNodes[0].nodeValue.replace(re2,"<br/>"):'';
   sName+="<tr class=bgc"+(cC?0:1)+"><th>"+t1+"</th><td>"+t2+"</td></tr>";
//   sName+=banded(cC,1)+t1+banded(cC,2)+t2+"</div></td></tr></table>";
  }
  sName+="</table>";
  sName+="</nobr>";
 }
}
x=xmlDoc.getElementsByTagName("ACSROF");
if(x.length&&chlnk(x)){
 var xx=x[0].getElementsByTagName("M");
 if(xx){
  sName+="<nobr id='cv_desc'>";
  sName+="<table>";
  sName+="<caption>Accessory Of:</caption>";
  for(var j=0,cC=true;j<xx.length;j++,cC=!cC){
   var s01="",s02="";
   var a01=xx[j].childNodes[0].childNodes[0];
   if(a01) s01=a01.nodeValue;
   while(true){
    var ln=s01.lastIndexOf('/');
    if(ln==-1) break;
    s01=s01.substring(0,ln)+s01.substring(ln+1);
   }
   var a02=xx[j].childNodes[1].childNodes[0];
   if(a02) s02=a02.nodeValue;
   sName+="<tr class=bgc"+(cC?0:1)+"><th>"+"<a href='#'>"+s01+"</th><td>"+s02+"</td></tr>";
//   sName+=banded(cC,1)+"<a href='#'>"+s01+banded(cC,2)+s02+"</div></td></tr></table>";
  }
  sName+="</table>";
  sName+="</nobr>";
 }
}
/*-------
x=xmlDoc.getElementsByTagName("RELPROD");
if(x.length){
  sName+="<fieldset><div class=ditm2>Related Products:</div></fieldset>";

  for(var j=0,cC=true;j<x.length;j++,cC=!cC){
   var s01='',s02='';
   var a01=x[j].childNodes[0].childNodes[0];
   if(a01) s01=a01.nodeValue;
   while(true){
    var ln=s01.lastIndexOf('/');
    if(ln==-1) break;
    s01=s01.substring(0,ln)+s01.substring(ln+1);
   }
   var a02=x[j].childNodes[1].childNodes[0];
   if(a02) s02=a02.nodeValue;
   sName+=banded(cC,1)+"<a href='#'>"+s01+banded(cC,2)+s02+"</div></td></tr></table>";
  }
//  sName+="<br/>";

 for(var j=0,cC=true;j<x.length;j++,cC=!cC){
  var t1=x[j].childNodes[0].hasChildNodes()?x[j].childNodes[0].childNodes[0].nodeValue:'';
  var t2=x[j].childNodes[1].hasChildNodes()?x[j].childNodes[1].childNodes[0].nodeValue.replace(re2,"<br/>"):'';
  sName+=banded(cC,1)+t1+banded(cC,2)+t2+"</div></td></tr></table>";
 }
}
*/
x=xmlDoc.getElementsByTagName("ESPEC");
if(x.length){
 var xx=x[0].getElementsByTagName("M");
 if(xx.length){
//  sName+="<nobr id='cv_desc'>";
//  sName+="<table>";
  for(var j=0,cC=false;j<xx.length;j++,cC=!cC){
   if(xx[j].previousSibling.nodeName=="T"){
    if(xx[j].previousSibling.hasChildNodes())
//     sName+="<div>"+xx[j].previousSibling.lastChild.nodeValue+"</div>";
      sName+="<br/><fieldset><div class=ditm2>"+xx[j].previousSibling.lastChild.nodeValue+"</div></fieldset>";
     cC=true;
    }
    var dclean=xx[j].childNodes[1].hasChildNodes()?xx[j].childNodes[1].childNodes[0].nodeValue.replace(re,"<br/>"):'';
//   sName+="<tr class=bgc"+(cC?0:1)+"><th>"+t1+"</th><td>"+t2+"</td></tr>";
    sName+=banded(cC,1);
    sName+=xx[j].childNodes[0].hasChildNodes()?xx[j].childNodes[0].childNodes[0].nodeValue+banded(cC,2)+dclean:banded(cC,2)+dclean;
    sName+="</div></td></tr></table>";


  }
//  sName+="</table>";
//  sName+="</nobr>";
 }
}
x=xmlDoc.getElementsByTagName("NAME");
if(x.length&&x[0].hasChildNodes()){
 sName+="<div class=cv_intro>"+x[0].childNodes[0].nodeValue.replace(re2,"<br/>")+"</div>";
}
return sName==''?innerText:sName;
}

function chlnk(o){
 if(!o) return false;
 var x=o[0].getElementsByTagName("M");
 if(!x) return false;
 var cn=x[0].childNodes[0].childNodes[0];
 if(!cn||cn.nodeValue=='') return false;
 return true;
}
function banded(a,b){
var bc=a?'#efefef':'white';
var cl=a?'':'2';
return b==1?"<table cellpadding=0 cellspacing=0 border=0 width='98%'><tr><td width='32%' bgcolor="+bc+"><div class=lbl"+cl+">&nbsp;":"</div></td><td width='66%' bgcolor="+bc+"><div class=dat"+cl+">";
}

function mk_act(tb,iid){
 document.getElementById("tb1").className='';
 document.getElementById("tb2").className='';
 document.getElementById("tb3").className='';
 document.getElementById("tb"+tb).className='active';
 cv_ajx('getTabPage?tb='+tb+'&iid='+iid,'cv_cntnt', 'getting content for tab '+tb+'. Wait...','Error');
}

//----------------
function createCookie(name,value,days){
 var expires='';
 if(days){
  var date=new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  expires="; expires="+date.toGMTString();
 }
 else
  expires="";
 document.cookie=name+"="+value+expires+"; path=/";
}

function readCookie(name){
 var nameEQ=name+"=";
 var ca=document.cookie.split(';');
 for(var i=0;i<ca.length;i++){
  var c=ca[i];
  while(c.charAt(0)==' ')
   c=c.substring(1,c.length);
  if(c.indexOf(nameEQ)==0)
   return c.substring(nameEQ.length,c.length);
 }
 return null;
}

function eraseCookie(name){
 createCookie(name,"",-1);
}

//----------------

//Author M.Davidov md at compuvest.com
var sIs=new Array("","one","two","three","four","five","six","seven","eight","nine");
var dIs=new Array("","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen");
var tIs=new Array("","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety");
var qIs=new Array("","thousand","million","billion");
function NtoW(){var x=document.getElementById("nsu").firstChild.nodeValue.split('\$');n2w(x[1]);}
function sdt(a){var s="";var j;var i=a%10;if(i>0)s=sIs[i];j=Math.floor((a%100)/10);if(j==1)s=dIs[i+1];else if(j>1&&j<10)s=tIs[j-1]+" "+s;i=Math.floor(a/100);if(i>0)s=sIs[i]+" hundred "+s;return s;}
function n2w(a){var i=0;var k=0;var s="";if(a){var t=a.split('.', 2);i=parseInt(t[0].replace(/,/g,""));}if(i>0 && i<2147483647){for(var j=0;j<4;j++){var k=i%1000;i=Math.floor(i/1000);if(k>0)s=sdt(k)+" "+qIs[j]+" "+s;}}k=parseInt(t[1],10);if(k<10&&t[1].length==1) k*=10;if(k>0)s+=" and "+k+" cents";document.getElementById("am").innerHTML="<i>"+s+"</i>";}

function isEmpty(s){return(s==null||s.length==0);}
function isDigit(s){return(s>='0'&&s<='9');}
function isInt(s){
 var ns='';
 for(var i=0;i<s.length;i++){
  ch=s.substring(i,i+1);
  if(isDigit(ch)) ns+=ch;
 }
 return(isEmpty(ns))?"0":ns;
}
function isNumber(s){
 if(s.length==0) return false;
 var validChars="0123456789";
 for(var i=0;i<s.length;i++){
  if(validChars.indexOf(s.charAt(i))==-1){return false;}
 }
 return true;
}
function toAlphaNumeric(s){
var newStr='';
for(var i=0;i<s.length;i++){
 ch=s.substring(i,i+1);
 if(ch=="\'") continue;
 if(ch>=" "&&ch<="~") newStr+=ch;
}
return newStr;
}
function trim(s) {
 return s.replace(/^\s+|\s+$/g,'');
}
function isEmail(s){
 if(s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
 return false;
}

function billtoshipp(){
 var o=document.Customer;
 o.shippingCompany.value=o.billingCompany.value;
 o.shippingFirstName.value=o.billingFirstName.value;
 o.shippingLastName.value=o.billingLastName.value;
 o.shippingAddress1.value=o.billingAddress1.value;
 o.shippingAddress2.value=o.billingAddress2.value;
 o.shippingCity.value=o.billingCity.value;
 o.shippingZip.value=o.billingZip.value;
 o.shippingZip4.value=o.billingZip4.value;
 o.shippingState.value=o.billingState.value;
 o.shippingCountry.value=o.billingCountry.value;
 o.shippingPhone.value=o.billingPhone.value;
 o.shippingCell.value=o.billingCell.value;
 o.shippingFax.value=o.billingFax.value;
 o.slip.checked=false;
 o.slip.disabled=true;
}
function blinds(){
 var o=document.Customer;
 o.shippingCompany.value='';
 o.shippingFirstName.value='';
 o.shippingLastName.value='';
 o.shippingAddress1.value='';
 o.shippingAddress2.value='';
 o.shippingCity.value='';
 o.shippingZip.value='';
 o.shippingZip4.value='';
 o.shippingState.value='';
 o.shippingPhone.value='';
 o.shippingCell.value='';
 o.shippingFax.value='';
 o.slip.disabled=false;
}
var validEmail = "Please enter a valid e-mail address.";
function isFormReadyOld(form){
 if(!isEmail(form.Email.value)){alert(validEmail);form.Email.focus();return false;}
 if(!form.Password.value){alert("Password cannot be empty.");form.Password.focus();return false;}
 return true;
}
function isFormReady(form){
 if(!isEmail(form.Email.value)){alert(validEmail);form.Email.focus();return false;}
 if(!form.Password.value){alert("Password cannot be empty.");form.Password.focus();return false;}
 if(form.vPassword.value!=form.Password.value){alert("Your passwords do not match.");form.vPassword.focus();return false;}
 return true;
}
function isFormReadyFog(form){
 if(!isEmail(form.Email.value)){alert(validEmail);form.Email.focus();return false;}
 return true;
}
function isFormDone(form){
 if(!form.Password.value){alert("Password cannot be empty.");form.Password.focus();return false;}
 if(form.vPassword.value!=form.Password.value){alert("Your passwords do not match.");form.vPassword.focus();return false;}
 if(!form.billingFirstName.value){alert("First Name are required.");form.billingFirstName.focus();return false;}
 if(!form.billingLastName.value){alert("Last Name are required.");form.billingLastName.focus();return false;}
 if(!form.billingAddress1.value){alert("Address are required.");form.billingAddress1.focus();return false;}
 if(!form.billingCountry.value){alert("Country are required.");form.billingCountry.focus();return false;}
 if(!form.billingCity.value){alert("City are required.");form.billingCity.focus();return false;}
 if(!form.billingState.value){alert("State are required.");form.billingState.focus();return false;}
 if(!form.billingZip.value){alert("Zip are required.");form.billingZip.focus();return false;}
 if(!form.billingPhone.value){alert("Phone are required.");form.billingPhone.focus();return false;}
 if(!form.shippingAddress1.value){alert("Address are required.");form.shippingAddress1.focus();return false;}
 if(!form.shippingCountry.value){alert("Country are required.");form.shippingCountry.focus();return false;}
 if(!form.shippingCity.value){alert("City are required.");form.shippingCity.focus();return false;}
 if(!form.shippingState.value){alert("State are required.");form.shippingState.focus();return false;}
 if(!form.shippingZip.value){alert("Zip are required.");form.shippingZip.focus();return false;}
 if(form.billingCountry.value=='US'&&!isNumber(form.billingZip.value)){alert("Invalid Billing Zip.");form.billingZip.focus();return false;}
 if(form.shippingCountry.value=='US'&&!isNumber(form.shippingZip.value)){alert("Invalid Shipping Zip.");form.shippingZip.focus();return false;}
 return true;
}
function isDoneR(form){
 if(!form.resellerCode.value){alert("Certificate are required.");form.resellerCode.focus();return false;}
 if(!form.billingFirstName.value){alert("First Name are required.");form.billingFirstName.focus();return false;}
 if(!form.billingLastName.value){alert("Last Name are required.");form.billingLastName.focus();return false;}
 if(!form.billingAddress1.value){alert("Address are required.");form.billingAddress1.focus();return false;}
 if(!form.billingCountry.value){alert("Country are required.");form.billingCountry.focus();return false;}
 if(!form.billingCity.value){alert("City are required.");form.billingCity.focus();return false;}
 if(!form.billingState.value){alert("State are required.");form.billingState.focus();return false;}
 if(!form.billingZip.value){alert("Zip are required.");form.billingZip.focus();return false;}
 if(!form.billingPhone.value){alert("Phone are required.");form.billingPhone.focus();return false;}
 if(!isEmail(form.Email.value)){alert(validEmail);form.Email.focus();return false;}
 if(!form.Password.value){alert("Password cannot be empty.");form.Password.focus();return false;}
 if(form.vPassword.value!=form.Password.value){alert("Your passwords do not match.");form.vPassword.focus();return false;}
 return true;
}

/* payment */
function ddtabcontent(tabinterfaceid){
 this.tabinterfaceid=tabinterfaceid
 this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a")
 this.enabletabpersistence=true
 this.hottabspositions=[]
 this.currentTabIndex=0
 this.subcontentids=[]
 this.revcontentids=[]
 this.selectedClassTarget="link"
}
ddtabcontent.prototype={
 expandit:function(tabid_or_position){
  var tabref=""
  try{
   if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel"))
    tabref=document.getElementById(tabid_or_position)
   else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel"))
    tabref=this.tabs[tabid_or_position]
  }catch(e){alert("Invalid Tab ID or position entered!")}
  if(tabref!="") this.expandtab(tabref)
 },
 setpersist:function(bool){this.enabletabpersistence=bool;},
 setselectedClassTarget:function(objstr){this.selectedClassTarget=objstr || "link"},
 getselectedClassTarget:function(tabref){return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode:tabref},
 urlparamselect:function(tabinterfaceid){
  var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)","i"))
  return (result==null)? null:parseInt(RegExp.$1)
 },
 expandtab:function(tabref){
  var subcontentid=tabref.getAttribute("rel")
//  for(var i=0;i<document.Payment.ship_opt.length;i++) document.Payment.ship_opt[i].checked=false;
  document.Payment.tabs.value=subcontentid;
  var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+",":"";
  this.expandsubcontent(subcontentid)
  this.expandrevcontent(associatedrevids)
  for(var c=0;c<this.tabs.length;c++){
   this.getselectedClassTarget(this.tabs[c]).className=(this.tabs[c].getAttribute("rel")==subcontentid)? "selected":"";
  }
  this.setcurrenttabindex(tabref.tabposition)
 },
 expandsubcontent:function(subcontentid){
  for (var i=0; i<this.subcontentids.length; i++){
   var subcontent=document.getElementById(this.subcontentids[i])
   subcontent.style.display=(subcontent.id==subcontentid)? "block":"none"
  }
 },
 expandrevcontent:function(associatedrevids){
  var allrevids=this.revcontentids
  for (var i=0; i<allrevids.length; i++){
   document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block":"none"
  }
 },
 setcurrenttabindex:function(tabposition){
  for(var i=0; i<this.hottabspositions.length; i++){
   if(tabposition==this.hottabspositions[i]){
    this.currentTabIndex=i
    break
   }
  }
 },
 init:function(automodeperiod){
  var selectedtab=-1
  var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid)
  this.automodeperiod=automodeperiod || 0
  for(var i=0; i<this.tabs.length; i++){
   this.tabs[i].tabposition=i
   if(this.tabs[i].getAttribute("rel")){
    var tabinstance=this
    this.hottabspositions[this.hottabspositions.length]=i
    this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel")
    this.tabs[i].onclick=function(){
     tabinstance.expandtab(this)
     return false
    }
    if(selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 &&
       !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
      selectedtab=i
    }
   }
  } //END for loop
  if (selectedtab!=-1)
   this.expandtab(this.tabs[selectedtab])
  else
   this.expandtab(this.tabs[this.hottabspositions[0]])
 } //END int() function
} //END Prototype

function isCreditCard(s){
 var ck=parseInt(s,10);
 if(!ck) return '';
 var sum=0,mul=1,l=s.length;
 for(var i=0;i<l;i++){
  var digit=s.substring(l-i-1,l-i);
  var tproduct=parseInt(digit,10)*mul;
  (tproduct>=10)? sum+=(tproduct%10)+1:sum+=tproduct;
  (mul==1)? mul++:mul--;
 }
 if(s.length!=''&&(sum%10)==0) return(s);
 else {
  alert("Check yours card number: "+s);
  document.Payment.CNumber.focus();
 }
 return '';
}

function ckblinds(){
 var o=document.Payment;
 if(!o.blind.checked){
  o.slip.checked=false;
  o.slip.disabled=true;
 }
 else{
  o.slip.disabled=false;
 }
}
function ck_ship_acc(){
 var o=document.Payment;
 if(o.useacc.checked){
  o.spb.value='';
  o.totb.value=o.totns.value;
 }
 else{
  o.spb.value='';
  o.desb.value='';
  o.totb.value='';
 }
 document.getElementById('desview').innerHTML='';
 if(o.ship_opt.length==undefined){o.ship_opt.checked=false;}
 else{for(var i=0;i<o.ship_opt.length;i++){o.ship_opt[i].checked=false;}}
}
function isPaymentDone(form){
 if(!form.totb.value){alert("Please choose one Shipping Methods!");return false;}
 if(form.useacc.checked){
  if(!form.shipaccount.value){alert("Shipping Account required!");form.shipaccount.focus();return false;}
 }
 if(form.tabs.value=="CC"||form.tabs.value=="PI"){
  if(!form.CNumber.value){alert("Credit card Number required!");form.CNumber.focus();return false;}
  if(!form.CExpMonth.value){alert("Credit card Month required!");form.CExpMonth.focus();return false;}
  if(!form.CExpYears.value){alert("Credit card Years required!");form.CExpYears.focus();return false;}
 }
 return true;
}
